Warning: mkdir(): No space left on device in /var/www/tg-me/post.php on line 37

Warning: file_put_contents(aCache/aDaily/post/dsproglib/--): Failed to open stream: No such file or directory in /var/www/tg-me/post.php on line 50
Библиотека дата-сайентиста | Data Science, Machine learning, анализ данных, машинное обучение | Telegram Webview: dsproglib/6471 -
Telegram Group & Telegram Channel
🔥 Команда дня: einsum или как реализовать multi-head self-attention без единого цикла

Если вы работаете с нейросетями, особенно с трансформерами, то, скорее всего, сталкивались с реализациями self-attention, переполненными циклами. Однако благодаря np.einsum можно выразить всю механику multi-head attention в компактной и векторизованной форме.

Вот пример реализации:
def multi_head_attention(X, W_q, W_k, W_v, W_o):  
d_k = W_k.shape[-1]
Q = np.einsum('si,hij->hsj', X, W_q) # (n_heads, seq_len, d_k)
K = np.einsum('si,hik->hsk', X, W_k)
V = np.einsum('si,hiv->hsv', X, W_v)
scores = Q @ K.transpose(0, 2, 1) / np.sqrt(d_k)
weights = softmax(scores, axis=-1)
output = weights @ V
projected = np.einsum('hsv,hvd->hsd', output, W_o)
return projected.transpose(1, 0, 2).reshape(seq_len, -1)


💡 einsum — мощный инструмент для выражения сложных операций с многомерными массивами. Особенно полезен, когда нужно точно контролировать свёртки и трансформации осей. В задачах NLP и computer vision это буквально незаменимая вещь.

📌 Почему стоит обратить внимание:
— Полная векторизация — минимум циклов, максимум скорости;
— Код ближе к математике, а значит — легче проверять;
— Можно выразить довольно сложные операции с тензорами в одной строке.

Библиотека дата-сайентиста #буст



tg-me.com/dsproglib/6471
Create:
Last Update:

🔥 Команда дня: einsum или как реализовать multi-head self-attention без единого цикла

Если вы работаете с нейросетями, особенно с трансформерами, то, скорее всего, сталкивались с реализациями self-attention, переполненными циклами. Однако благодаря np.einsum можно выразить всю механику multi-head attention в компактной и векторизованной форме.

Вот пример реализации:

def multi_head_attention(X, W_q, W_k, W_v, W_o):  
d_k = W_k.shape[-1]
Q = np.einsum('si,hij->hsj', X, W_q) # (n_heads, seq_len, d_k)
K = np.einsum('si,hik->hsk', X, W_k)
V = np.einsum('si,hiv->hsv', X, W_v)
scores = Q @ K.transpose(0, 2, 1) / np.sqrt(d_k)
weights = softmax(scores, axis=-1)
output = weights @ V
projected = np.einsum('hsv,hvd->hsd', output, W_o)
return projected.transpose(1, 0, 2).reshape(seq_len, -1)


💡 einsum — мощный инструмент для выражения сложных операций с многомерными массивами. Особенно полезен, когда нужно точно контролировать свёртки и трансформации осей. В задачах NLP и computer vision это буквально незаменимая вещь.

📌 Почему стоит обратить внимание:
— Полная векторизация — минимум циклов, максимум скорости;
— Код ближе к математике, а значит — легче проверять;
— Можно выразить довольно сложные операции с тензорами в одной строке.

Библиотека дата-сайентиста #буст

BY Библиотека дата-сайентиста | Data Science, Machine learning, анализ данных, машинное обучение


Warning: Undefined variable $i in /var/www/tg-me/post.php on line 283

Share with your friend now:
tg-me.com/dsproglib/6471

View MORE
Open in Telegram


Библиотека дата сайентиста | Data Science Machine learning анализ данных машинное обучение Telegram | DID YOU KNOW?

Date: |

Export WhatsApp stickers to Telegram on iPhone

You can’t. What you can do, though, is use WhatsApp’s and Telegram’s web platforms to transfer stickers. It’s easy, but might take a while.Open WhatsApp in your browser, find a sticker you like in a chat, and right-click on it to save it as an image. The file won’t be a picture, though—it’s a webpage and will have a .webp extension. Don’t be scared, this is the way. Repeat this step to save as many stickers as you want.Then, open Telegram in your browser and go into your Saved messages chat. Just as you’d share a file with a friend, click the Share file button on the bottom left of the chat window (it looks like a dog-eared paper), and select the .webp files you downloaded. Click Open and you’ll see your stickers in your Saved messages chat. This is now your sticker depository. To use them, forward them as you would a message from one chat to the other: by clicking or long-pressing on the sticker, and then choosing Forward.

Spiking bond yields driving sharp losses in tech stocks

A spike in interest rates since the start of the year has accelerated a rotation out of high-growth technology stocks and into value stocks poised to benefit from a reopening of the economy. The Nasdaq has fallen more than 10% over the past month as the Dow has soared to record highs, with a spike in the 10-year US Treasury yield acting as the main catalyst. It recently surged to a cycle high of more than 1.60% after starting the year below 1%. But according to Jim Paulsen, the Leuthold Group's chief investment strategist, rising interest rates do not represent a long-term threat to the stock market. Paulsen expects the 10-year yield to cross 2% by the end of the year. A spike in interest rates and its impact on the stock market depends on the economic backdrop, according to Paulsen. Rising interest rates amid a strengthening economy "may prove no challenge at all for stocks," Paulsen said.

Библиотека дата сайентиста | Data Science Machine learning анализ данных машинное обучение from hk


Telegram Библиотека дата-сайентиста | Data Science, Machine learning, анализ данных, машинное обучение
FROM USA